package cn.edu.sgu.www.mhxysy.service.fabao.impl;

import cn.edu.sgu.www.mhxysy.pager.Pager;
import cn.edu.sgu.www.mhxysy.entity.fabao.FabaoSixiangAttributeEffect;
import cn.edu.sgu.www.mhxysy.mapper.fabao.FabaoSixiangAttributeEffectMapper;
import cn.edu.sgu.www.mhxysy.pager.fabao.FabaoSixiangAttributeEffectPager;
import cn.edu.sgu.www.mhxysy.service.fabao.FabaoSixiangAttributeEffectService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class FabaoSixiangAttributeEffectServiceImpl implements FabaoSixiangAttributeEffectService {

    private final FabaoSixiangAttributeEffectMapper sixiangAttributeEffectMapper;

    @Autowired
    public FabaoSixiangAttributeEffectServiceImpl(FabaoSixiangAttributeEffectMapper sixiangAttributeEffectMapper) {
        this.sixiangAttributeEffectMapper = sixiangAttributeEffectMapper;
    }

    @Override
    public void insert(FabaoSixiangAttributeEffect fabaoSixiangAttributeEffect) {
        fabaoSixiangAttributeEffect.setId(null);

        sixiangAttributeEffectMapper.insert(fabaoSixiangAttributeEffect);
    }

    @Override
    public void deleteById(Integer id) {
        sixiangAttributeEffectMapper.deleteById(id);
    }

    @Override
    public void updateById(FabaoSixiangAttributeEffect fabaoSixiangAttributeEffect) {
        sixiangAttributeEffectMapper.updateById(fabaoSixiangAttributeEffect);
    }

    @Override
    public Page<FabaoSixiangAttributeEffect> selectByPage(FabaoSixiangAttributeEffectPager pager) {
        QueryWrapper<FabaoSixiangAttributeEffect> queryWrapper = new QueryWrapper<>();
        Page<FabaoSixiangAttributeEffect> page = Pager.ofPage(pager);

        queryWrapper.eq(
                pager.getSixiangId() != null,
                "sixiang_id", pager.getSixiangId()
        );

        return sixiangAttributeEffectMapper.selectPage(page, queryWrapper);
    }

}